package com.elcom.roaming.module.collection.match;

import com.elcom.roaming.common.config.ConfigModule;
import com.elcom.roaming.common.util.match.ObjectKey;

public class UIKey extends ObjectKey {
	int seq;
	String orgTransId;
	String termTransId;
	String gtCalled;
	String gtCalling;
	char type;
	
	public UIKey(int seq, char type, String time, String orgTransId, String termTransId, String gtCalled, String gtCalling) {
		this.seq = seq;
		this.setPutTime(time);
		this.type = type;
		this.orgTransId = orgTransId;
		this.termTransId = termTransId;
		this.gtCalled = gtCalled;
		this.gtCalling = gtCalling;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof UIKey)) return false;
		UIKey cmpObj = (UIKey) obj;
		
		if (this == cmpObj) return true;
		
		if (this.getPutTimeInMs() - cmpObj.getPutTimeInMs() < ConfigModule.MISS_CALL_TIMEOUT * 1000 
				&& cmpObj.getOrgTransId().equals(this.getTermTransId())
				&& cmpObj.getGtCalling().equals(this.getGtCalled())) return true;
		
		return false;
	}

	public int getSeq() {
		return seq;
	}

	public String getOrgTransId() {
		return orgTransId;
	}

	public String getTermTransId() {
		return termTransId;
	}

	public String getGtCalled() {
		return gtCalled;
	}

	public String getGtCalling() {
		return gtCalling;
	}

	@Override
	public String toString() {
		return "seq=" + seq +
				"|time=" + getPutTime() +
				"|orgTransId=" + orgTransId +
				"|termTransId=" + termTransId +
				"|gtCalled=" + gtCalled +
				"|gtCalling=" + gtCalling;
	}

	@Override
	public int hashCode() {
		if (type == UIValue.U0)	return getOrgTransId().hashCode() * gtCalling.hashCode();
		else return getTermTransId().hashCode() * gtCalled.hashCode();
	}
	
}
